<template>
  <div class="app-container">
    <div class="head-container">
      入库单号:
      <el-input
        clearable
        v-model="listQuery.Inboundordernumber"
        size="small"
        placeholder="入库单号..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      外部单号:
      <el-input
        clearable
        v-model="listQuery.Externaltrackingnumber"
        size="small"
        placeholder="外部单号..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      预约单号:
      <el-input
        clearable
        v-model="listQuery.Externaltrackingnumber"
        size="small"
        placeholder="预约单号..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      入库库位:
      <el-input
        clearable
        size="small"
        placeholder="入库库位..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-select>
        <el-option>入库时间</el-option>
        <el-option>操作时间</el-option>
      </el-select>
      <el-radio v-model="radio" label="1">今天</el-radio>
      <el-radio v-model="radio" label="2">近7天</el-radio>
      <el-radio v-model="radio" label="3">近30天</el-radio>
      <el-radio v-model="radio" label="4">三个月前</el-radio>
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-search"
        @click="handleFilter"
        >搜索</el-button
      >
      <el-button class="filter-item" size="mini" @click="handleFilter"
        >清空</el-button
      >
      <br />
      <br />
      &nbsp;&nbsp; 承运商:
      <el-input
        clearable
        v-model="listQuery.Carriers"
        size="small"
        placeholder="承运商..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      运单号:
      <el-input
        clearable
        v-model="listQuery.Trackingnumber"
        size="small"
        placeholder="运单号..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      商品:
      <el-input
        clearable
        size="small"
        placeholder="商品..."
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      从：
      <el-date-picker v-model="value1" type="date" placeholder="选择日期">
      </el-date-picker>
      到：
      <el-date-picker v-model="value1" type="date" placeholder="选择日期">
      </el-date-picker>
      <el-select placeholder="更多">
        <el-option>入库时间</el-option>
        <el-option>操作时间</el-option>
      </el-select>
      <br />
      <br />
      <el-button
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="Purchasingwarehousingfunction"
        >采购入库</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        >验货入库</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        >打印采购入库单</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        >打印条码</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-edit"
        @click="handleCreate()"
        >新增</el-button
      >
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-edit"
        @click="handleUpdate()"
        >修改</el-button
      >
      <el-button
        slot="reference"
        class="filter-item"
        type="primary"
        icon="el-icon-delete"
        size="mini"
        @click="handleDownload()"
        >导出</el-button
      >
      <el-button
        slot="reference"
        class="filter-item"
        type="danger"
        icon="el-icon-delete"
        size="mini"
        @click="handleDelete()"
        >删除</el-button
      >
      <input type="file" @change="beforeUpload" accept=".xls,.xlsx" required />
      <el-button
        slot="reference"
        class="filter-item"
        type="warning"
        icon="el-icon-s-data"
        size="mini"
        @click="uploadFile()"
        >导入</el-button
      >
      <!-- <el-table
        :data="tableData"
        border
        highlight-current-row
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column
          v-for="item of tableHeader"
          :key="item"
          :prop="item"
          :label="item"
        />
      </el-table> -->
      &nbsp;&nbsp;
      <span style="color: blue"> 商品总数: </span>
    </div>

    <el-dialog
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
      @close="cancel()"
      :title="formTitle"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        size="medium"
        label-width="100px"
      >
        <el-form-item label="供应商" prop="vendor">
          <el-input
            v-model="form.vendor"
            placeholder="请输入供应商"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="预约单申请时间" prop="appointmentrequesttime">
          <el-input
            v-model="form.appointmentrequesttime"
            placeholder="请输入预约单申请时间"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品总额" prop="totalamount">
          <el-input
            v-model="form.totalamount"
            placeholder="请输入商品总额"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品总数" prop="totalnumberofunits">
          <el-input
            v-model="form.totalnumberofunits"
            placeholder="请输入商品总数"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="运单号" prop="trackingnumber">
          <el-input
            v-model="form.trackingnumber"
            placeholder="请输入运单号"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="承运商" prop="carriers">
          <el-input
            v-model="form.carriers"
            placeholder="请输入承运商"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品总体积" prop="totalvolumeof">
          <el-input
            v-model="form.totalvolumeof"
            placeholder="请输入商品总体积"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="外部单号" prop="externaltrackingnumber">
          <el-input
            v-model="form.externaltrackingnumber"
            placeholder="请输入外部单号"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品总重量" prop="totalweightof">
          <el-input
            v-model="form.totalweightof"
            placeholder="请输入商品总重量"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="预约单号" prop="reservationnumber">
          <el-input
            v-model="form.reservationnumber"
            placeholder="请输入预约单号"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="入库时间" prop="Inboundtime">
          <el-input
            v-model="form.Inboundtime"
            placeholder="请输入入库时间"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="入库单号" prop="Inboundordernumber">
          <el-input
            v-model="form.Inboundordernumber"
            placeholder="请输入入库单号"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="操作员" prop="operator">
          <el-input
            v-model="form.operator"
            placeholder="请输入操作员"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
        <el-form-item label="单据备注" prop="documentremarks">
          <el-input
            v-model="form.documentremarks"
            placeholder="请输入单据备注"
            clearable
            :style="{ width: '100%' }"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button size="small" type="text" @click="cancel">取消</el-button>
        <el-button
          size="small"
          v-loading="formLoading"
          type="primary"
          @click="save"
          >确认</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="dialogFormVisibledan"
      @close="cancel()"
      :title="formTitledan"
      style="width: 3600px; margin-left: -600px"
      draggable
    >
      <el-select>
        <el-option>预约单号</el-option>
        <el-option>外部单号</el-option>
      </el-select>
      <el-input
        clearable
        size="small"
        placeholder="单号..."
        style="width: 200px"
        class="filter-item"
      />
      承运商：
      <el-input
        clearable
        size="small"
        placeholder="承运商..."
        style="width: 200px"
        class="filter-item"
      />
      供应商：
      <el-select>
        <el-option>1</el-option>
        <el-option>1</el-option>
      </el-select>
      <el-select>
        <el-option>申请时间</el-option>
        <el-option>预约时间</el-option>
      </el-select>
      <el-radio v-model="radio" label="1">今天</el-radio>
      <el-radio v-model="radio" label="2">近7天</el-radio>
      <el-radio v-model="radio" label="3">近30天</el-radio>
      <el-radio v-model="radio" label="4">三个月前</el-radio>
      <el-button
        class="filter-item"
        size="mini"
        type="success"
        icon="el-icon-search"
        >查询</el-button
      >
      <el-button class="filter-item" size="mini">清空</el-button>
      <br />
      <br />
      入库状态：
      <el-select style="width: 140px">
        <el-option>在途</el-option>
        <el-option>部分入库</el-option>
      </el-select>
      运单号：
      <el-input
        clearable
        size="small"
        placeholder="运单号..."
        style="width: 180px"
        class="filter-item"
      />
      商品：
      <el-input
        clearable
        size="small"
        placeholder="商品..."
        style="width: 200px"
        class="filter-item"
      />
      从：
      <el-date-picker v-model="value1" type="date" placeholder="选择日期">
      </el-date-picker>
      到：
      <el-date-picker v-model="value1" type="date" placeholder="选择日期">
      </el-date-picker>
      <el-select placeholder="更多">
        <el-option>入库时间</el-option>
        <el-option>操作时间</el-option>
      </el-select>
      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        size="small"
        style="width: 100%; font-size: 14px"
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
      >
        <el-table-column type="selection" width="88px"></el-table-column>
        <el-table-column label="图示" prop="vendor" align="center" />
        <el-table-column
          label="状态"
          prop="appointmentrequesttime"
          align="center"
          width="144px"
        />
        <el-table-column label="申请时间" prop="totalamount" align="center" />
        <el-table-column
          label="单据编码"
          prop="totalnumberofunits"
          align="center"
        />
        <el-table-column
          label="仓库"
          prop="trackingnumber"
          align="center"
          width="144px"
        />
        <el-table-column
          label="供应商"
          prop="carriers"
          align="center"
          width="144px"
        />
        <el-table-column label="仓库" prop="totalvolumeof" align="center" />
        <el-table-column
          label="入库库位"
          prop="externaltrackingnumber"
          align="center"
        />
        <el-table-column label="入库库位" prop="totalweightof" align="center" />
        <el-table-column
          label="承运商"
          prop="reservationnumber"
          align="center"
        />
        <el-table-column label="运单号" prop="Inboundtime" align="center" />
        <el-table-column
          label="运单号"
          prop="Inboundordernumber"
          align="center"
        />
        <el-table-column label="外部单号" prop="operator" align="center" />
        <el-table-column label="备注" prop="documentremarks" align="center" />
        <el-table-column label="申请人" prop="documentremarks" align="center" />
        <el-table-column
          label="商品编码"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="条码"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="商品名称"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="规格编码"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="规格值"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="单位"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="预约数量"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="待入库数量"
          prop="documentremarks"
          align="center"
          width="144px"
        />
        <el-table-column
          label="实际入库数量"
          prop="documentremarks"
          align="center"
          width="144px"
        />
      </el-table>
      <div slot="footer" align="center">
        <el-button size="small" type="text" @click="canceldan">取消</el-button>
        <el-button
          size="small"
          v-loading="formLoading"
          type="primary"
          @click="Purchasingwarehousingfunctiondan"
          >确认</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="dialogFormVisibledanzo"
      @close="cancel()"
      :title="formTitledanzo"
      style="width: 3600px; margin-left: -600px"
      draggable
    >
      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        size="small"
        style="width: 100%; font-size: 14px"
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
      >
        <el-table-column type="selection" width="88px"></el-table-column>
        <el-table-column label="图示" prop="vendor" align="center" />
        <el-table-column
          label="预约单申请时间"
          prop="appointmentrequesttime"
          align="center"
          width="144px"
        />
        <el-table-column label="状态" prop="totalamount" align="center" />
        <el-table-column
          label="商品总数"
          prop="totalnumberofunits"
          align="center"
        />
        <el-table-column
          label="申请时间"
          prop="trackingnumber"
          align="center"
          width="144px"
        />
        <el-table-column
          label="单据编码"
          prop="carriers"
          align="center"
          width="144px"
        />
        <el-table-column label="仓库" prop="totalvolumeof" align="center" />
        <el-table-column
          label="供应商"
          prop="externaltrackingnumber"
          align="center"
        />
        <el-table-column label="入库库位" prop="totalweightof" align="center" />
        <el-table-column
          label="承运商"
          prop="reservationnumber"
          align="center"
        />
        <el-table-column label="运单号" prop="Inboundtime" align="center" />
        <el-table-column
          label="入库单号"
          prop="Inboundordernumber"
          align="center"
        />
        <el-table-column label="外部单号" prop="operator" align="center" />
        <el-table-column label="备注" prop="documentremarks" align="center" />
        <el-table-column label="申请人" prop="documentremarks" align="center" />
        <el-table-column
          label="商品编码"
          prop="documentremarks"
          align="center"
          width="144px"
        />
      </el-table>
      <div slot="footer" align="center">
        <el-button size="small" type="text" @click="canceldanzo"
          >取消</el-button
        >
        <el-button size="small" v-loading="formLoading" type="primary"
          >保存</el-button
        >
      </div>
    </el-dialog>

    <el-table
      ref="multipleTable"
      v-loading="listLoading"
      :data="list"
      size="small"
      style="width: 100%; font-size: 18px"
      @sort-change="sortChange"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
    >
      <el-table-column type="selection" width="44px"></el-table-column>
      <el-table-column label="供应商" prop="vendor" align="center" />
      <el-table-column
        label="预约单申请时间"
        prop="appointmentrequesttime"
        align="center"
        width="200px"
      />
      <el-table-column label="商品总额" prop="totalamount" align="center" />
      <el-table-column
        label="商品总数"
        prop="totalnumberofunits"
        align="center"
      />
      <el-table-column label="运单号" prop="trackingnumber" align="center" />
      <el-table-column label="承运商" prop="carriers" align="center" />
      <el-table-column label="商品总体积" prop="totalvolumeof" align="center" />
      <el-table-column
        label="外部单号"
        prop="externaltrackingnumber"
        align="center"
      />
      <el-table-column label="商品总重量" prop="totalweightof" align="center" />
      <el-table-column
        label="预约单号"
        prop="reservationnumber"
        align="center"
      />
      <el-table-column label="入库时间" prop="inboundtime" align="center" />
      <el-table-column
        label="入库单号"
        prop="inboundordernumber"
        align="center"
      />
      <el-table-column label="操作员" prop="operator" align="center" />
      <el-table-column label="单据备注" prop="documentremarks" align="center" />
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button
            type="primary"
            size="mini"
            @click="handleUpdate(row)"
            icon="el-icon-edit"
          />
          <el-button
            type="danger"
            size="mini"
            @click="handleDelete(row)"
            icon="el-icon-delete"
          />
        </template>
      </el-table-column>
    </el-table>
    <div style="color: red">合计</div>
    <pagination
      v-show="totalCount > 0"
      :total="totalCount"
      :page.sync="page"
      :limit.sync="listQuery.MaxResultCount"
      @pagination="getList"
    />
  </div>
</template>
<script>
import Pagination from "@/components/Pagination";
import permission from "@/directive/permission/index.js";
const defaultForm = {
  id: null,
  vendor: null,
  appointmentrequesttime: null,
  totalamount: null,
  totalnumberofunits: null,
  trackingnumber: null,
  carriers: null,
  totalvolumeof: null,
  externaltrackingnumber: null,
  totalweightof: null,
  reservationnumber: null,
  Inboundtime: null,
  Inboundordernumber: null,
  operator: null,
  documentremarks: null,
};
export default {
  name: "procurement",
  components: {
    Pagination,
  },
  directives: {
    permission,
  },
  props: [],
  data() {
    return {
      rules: {
        vendor: [
          {
            required: true,
            message: "请输入供应商",
            trigger: "blur",
          },
        ],
        appointmentrequesttime: [
          {
            required: true,
            message: "请输入预约单申请时间",
            trigger: "blur",
          },
        ],
        totalamount: [
          {
            required: true,
            message: "请输入商品总额",
            trigger: "blur",
          },
        ],
        totalnumberofunits: [
          {
            required: true,
            message: "请输入商品总数",
            trigger: "blur",
          },
        ],
        trackingnumber: [
          {
            required: true,
            message: "请输入运单号",
            trigger: "blur",
          },
        ],
        carriers: [
          {
            required: true,
            message: "请输入承运商",
            trigger: "blur",
          },
        ],
        totalvolumeof: [
          {
            required: true,
            message: "请输入商品总体积",
            trigger: "blur",
          },
        ],
        externaltrackingnumber: [
          {
            required: true,
            message: "请输入外部单号",
            trigger: "blur",
          },
        ],
        totalweightof: [
          {
            required: true,
            message: "请输入商品总重量",
            trigger: "blur",
          },
        ],
        reservationnumber: [
          {
            required: true,
            message: "请输入预约单号",
            trigger: "blur",
          },
        ],
        Inboundtime: [
          {
            required: true,
            message: "请输入入库时间",
            trigger: "blur",
          },
        ],
        Inboundordernumber: [
          {
            required: true,
            message: "请输入入库单号",
            trigger: "blur",
          },
        ],
        operator: [
          {
            required: true,
            message: "请输入操作员",
            trigger: "blur",
          },
        ],
        documentremarks: [
          {
            required: true,
            message: "请输入单据备注",
            trigger: "blur",
          },
        ],
      },
      form: Object.assign({}, defaultForm),
      list: null,
      totalCount: 0,
      listLoading: true,
      formLoading: false,
      listQuery: {
        Filter: "",
        Sorting: "",
        SkipCount: 0,
        MaxResultCount: 10,
      },
      page: 1,
      dialogFormVisible: false,
      multipleSelection: [],
      formTitle: "",
      isEdit: false,
      formTitledan: "",
      dialogFormVisibledan: false,
      dialogFormVisibledanzo: false,
      tableData: [],
      tableHeader: [],
      file: null,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    getList() {
      this.listLoading = true;
      this.listQuery.SkipCount =
        (this.page - 1) * this.listQuery.MaxResultCount;
      this.$axios
        .gets("/api/business/procurement", this.listQuery)
        .then((response) => {
          this.list = response.items;
          this.totalCount = response.totalCount;
          this.listLoading = false;
        });
    },
    fetchData(id) {
      this.$axios.gets("/api/business/procurement/" + id).then((response) => {
        this.form = response;
      });
    },
    handleFilter() {
      this.page = 1;
      this.getList();
    },
    handleCreate() {
      this.formTitle = "新增采购入库单";
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    handleDelete(row) {
      var params = [];
      let alert = "";
      if (row) {
        params.push(row.id);
        alert = row.name;
      } else {
        if (this.multipleSelection.length === 0) {
          this.$message({
            message: "未选择",
            type: "warning",
          });
          return;
        }
        this.multipleSelection.forEach((element) => {
          let id = element.id;
          params.push(id);
        });
        alert = "选中项";
      }
      this.$confirm("是否删除" + alert + "?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .posts("/api/business/procurement/delete", params)
            .then((response) => {
              this.$notify({
                title: "成功",
                message: "删除成功",
                type: "success",
                duration: 2000,
              });
              this.getList();
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleUpdate(row) {
      this.formTitle = "修改采购入库单";
      this.isEdit = true;
      if (row) {
        this.fetchData(row.id);
        this.dialogFormVisible = true;
      } else {
        if (this.multipleSelection.length != 1) {
          this.$message({
            message: "编辑必须选择单行",
            type: "warning",
          });
          return;
        } else {
          this.fetchData(this.multipleSelection[0].id);
          this.dialogFormVisible = true;
        }
      }
    },
    save() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.formLoading = true;
          this.form.roleNames = this.checkedRole;
          if (this.isEdit) {
            this.$axios
              .posts("/api/business/procurement/data-post", this.form)
              .then((response) => {
                this.formLoading = false;
                this.$notify({
                  title: "成功",
                  message: "更新成功",
                  type: "success",
                  duration: 2000,
                });
                this.dialogFormVisible = false;
                this.getList();
              })
              .catch(() => {
                this.formLoading = false;
              });
          } else {
            this.$axios
              .posts("/api/business/procurement/data-post", this.form)
              .then((response) => {
                this.formLoading = false;
                this.$notify({
                  title: "成功",
                  message: "新增成功",
                  type: "success",
                  duration: 2000,
                });
                this.dialogFormVisible = false;
                this.getList();
              })
              .catch(() => {
                this.formLoading = false;
              });
          }
        }
      });
    },
    //#region 导出
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = [
          "承运商",
          "供应商",
          "预约单申请时间",
          "外部单号",
          "商品总数",
          "操作员",
          "入库单号",
          "入库时间",
          "商品总重量",
          "单据备注",
          "预约单号",
          "商品总额",
          "运单号",
          // "locationcoding",
          // "locationname",
          // "locationtype",
          // "usagemode",
          // "locationength",
          // "locationwidth",
          // "loadbearingofwarehouselocation",
          // "lockpriority",
          // "prioritycommodity",
          // "locationheight",
          // "locationvolume",
        ];
        const filterVal = [
          "carriers",
          "vendor",
          "appointmentrequesttime",
          "externaltrackingnumber",
          "totalnumberofunits",
          "operator",
          "inboundordernumber",
          "inboundtime",
          "totalweightof",
          "documentremarks",
          "reservationnumber",
          "totalvolumeof",
          "trackingnumber",
        ];
        const list = this.list;
        const data = this.formatJson(filterVal, list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: this.filename,
          autoWidth: this.autoWidth,
          bookType: this.bookType,
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
    //#endregion
    Purchasingwarehousingfunction() {
      this.formTitledan = "选择预约单";
      this.dialogFormVisibledan = true;
    },
    Purchasingwarehousingfunctiondan() {
      this.formTitledanzo = "采购入库";
      this.dialogFormVisibledan = false;
      this.dialogFormVisibledanzo = true;
    },
    //#region 导入
    beforeUpload(event) {
      this.file = event.target.files[0];
    },
    uploadFile() {
      const formData = new FormData();
      formData.append("file", this.file); // 'file' 是后台接收文件的键名

      this.$axios
        .posts("/api/business/Procurement/ImportExcel-post", formData, {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        })
        .then((response) => {
          console.log(response);
          // 处理成功响应
          this.$notify({
            title: "成功",
            message: "导入成功",
            type: "success",
            duration: 2000,
          });
          this.getList();

          this.handleSuccess(response.data); // 假设返回的数据包含 results 和 header

          this.getList();
        });
    },

    handleSuccess(data) {
      this.tableData = data.results;
      this.tableHeader = data.header;
      console.log(this.tableData);
      this.$notify({
        title: "成功",
        message: "导入成功",
        type: "success",
        duration: 2000,
      });
      this.getList();
    },
    //#endregion

    sortChange(data) {
      const { prop, order } = data;
      if (!prop || !order) {
        this.handleFilter();
        return;
      }
      this.listQuery.Sorting = prop + " " + order;
      this.handleFilter();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    cancel() {
      this.form = Object.assign({}, defaultForm);
      this.dialogFormVisible = false;
      this.$refs.form.clearValidate();
    },
    canceldan() {
      this.dialogFormVisibledan = false;
      this.$refs.form.clearValidate();
    },
    canceldanzo() {
      this.dialogFormVisibledanzo = false;
      this.$refs.form.clearValidate();
    },
  },
};
</script>
<style>
</style>
